package com.boot.jexl;

import cn.hutool.extra.expression.ExpressionEngine;
import cn.hutool.extra.expression.ExpressionUtil;
import org.apache.commons.jexl3.JexlBuilder;
import org.apache.commons.jexl3.JexlEngine;
import org.apache.commons.jexl3.JexlExpression;
import org.apache.commons.jexl3.MapContext;

import java.util.HashMap;
import java.util.Map;

public class JexlTester {

    public static void main(String[] args) {
//        JexlBuilder jexlBuilder = new JexlBuilder();
//        JexlEngine jexlEngine = jexlBuilder.create();
        String expressionStr = "a > 1 and b>=2 and c <= 3 ";
//        JexlExpression expression = jexlEngine.createExpression(expressionStr);
//        MapContext mapContext = new MapContext();
//        mapContext.set("a", 2);
//        mapContext.set("b", 3);
//        mapContext.set("c", 3);
//        Object evaluate = expression.evaluate(mapContext);
//        System.out.println(String.format("result:%s", evaluate));

        Map<String,Object> map = new HashMap<>();
        map.put("a", 2);
        map.put("b", 3);
        map.put("c", 3);
        ExpressionEngine engine = ExpressionUtil.getEngine();
        Object eval = ExpressionUtil.eval(expressionStr, map);
        System.out.println(String.format("result:%s", eval));
        String s= "<p>aaaaa <p>bbbbbbbbbb <p>cccccccc</p> <br/> </p></p>";
        System.out.println(
                s.replaceAll("\\&[a-zA-Z]{0,9};", "").replaceAll("<[^>]*>", "\n")
        );
    }
}
